//
//  myWindow.m
//  ufo_application_macosx
//
//  Created by czcomt on 12-5-22.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ufoDelegate.h"
#import <Cocoa/Cocoa.h>
#include "system.h"

extern UFOAPP_INFO g_appInfo;

@implementation ufoAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{   
    [window makeKeyAndOrderFront: nil];
    //[view setWantsLayer:YES];
}

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    ufoSetupAppInfo(&g_appInfo);
    int width = g_appInfo.width*ufoGetDPI();
    int height = g_appInfo.height*ufoGetDPI();
    
    int style = 0;
    if (g_appInfo.winStyle == STANDARD_WIN)
        style = NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask;
    else
        style = NSBorderlessWindowMask;
    
     view = [[ufoView alloc] initWithFrame:NSMakeRect(0,0,width,height) ];
     NSRect visibleRect = [[NSScreen mainScreen] visibleFrame];
     
     window = [[ufoWindow alloc] initWithContentRect:NSMakeRect((visibleRect.size.width - width)/2, (visibleRect.size.height - height)/2, width, height)
     styleMask:style
     backing:NSBackingStoreBuffered
     defer:YES];
     
    [window setTitle:@"ufoapp"];
    if (g_appInfo.winStyle == LAYERED_WIN)
        [window setOpaque:NO];
    else
        [window setOpaque:YES];
    
    [window setBackgroundColor:NSColor.clearColor];
    [window setHasShadow:YES];
    [window makeFirstResponder:view];
    //[window setIgnoresMouseEvents:YES];
    //[window setAlphaValue:0.6f];
    
    [view setAcceptsTouchEvents:NO];
    [view setAutoresizingMask:NSViewHeightSizable|NSViewWidthSizable];
    
    //[[window contentView] setWantsLayer:YES];
    
    [[window contentView] addSubview:view];
    
    
    //NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 200, 30)];
    //[view addSubview:textField];
}

@end